<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>编辑线路详细信息</title>
<link type="text/css" href="/res/app/admin/css/common.css" rel="stylesheet" />
<script type="text/javascript" src="/res/js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="/res/frame/js/php.js"></script>
<script type="text/javascript" src="/res/js/lib/jquery.upload.js"></script>

<script>
/**
 * 选中图片为线路主图片
 */
function choose(id)
{
    var src = $("#"+id).attr('src');
    $("#ico").val(src);
    $("#ico_view").attr("src",src);
}
function del(id)
{
    var src = $("#"+id).attr('src');
    $.ajax({
            url:'/adminweb/w-route/delImage?id={route.id}',
            data:'ico='+src,
            type:'post',
            dataType:'json',
            success:function (json){
                    if(json.success)
                    {
                        alert("删除成功");
                        window.location.reload();
                    }else{
                        alert("删除失败");
                        }
                    
            }

        })
}
</script>


</head>
<body>
<form action="{url}" method="post">
    <center>
        <table summary="Form table" border="1" bgcolor="#c0c0c0" cellpadding="2"  width="100%"cellspacing="1">
            <tr>
            <td bgcolor="#000080" style="border-style: none;"><font color="#ffffff"><b>线路图片</b></font></td>
            </tr>
            <tr>
            <td style="border-style: none;">
            <fieldset>
                <legend ><b>线路名</b></legend>
                <center>
                    <input type="text" style="width: 470px;" disabled="disabled" name="route_name" id="route_name" value="{route.name}"/>
                 </center>
           </fieldset>      </td>
        </tr>
        
        <tr>
            <td style="border-style: none;">
            <fieldset>
                <legend ><b>线路图片</b></legend>
                <center>
                    <img id="ico_view" src="{route.ico}"/>
                    <br />
                    <input type="text" style="width: 470px;" readonly="readonly" name="ico" id="ico" value="{route.ico}"/>
                    <input type="button" value="显示图片" onclick='javascript:$("#ico_view").attr("src",$("#ico").val());' />
                 </center>
           </fieldset>      </td>
        </tr>
        
        <tr>
            <td style="border-style: none;">
            <fieldset>
                <legend ><strong>已有图片</strong></legend>
                <center>
                  <table>
                   <!-- FOREACH image_list -->
                    <tr>
                      <td><img title="{ROWVALUE}" id="image_{ROWKEY}" src="/res/upload/image/route/{parent.route.id}/{ROWVALUE}" 
                        onclick="choose('image_{ROWKEY}');"                      
                      />{ROWVALUE}</td>
                      <td><input type="button" value="选择为主图片" onclick="choose('image_{ROWKEY}');"  />
                          <input type="button" value="删除" onclick="del('image_{ROWKEY}');"  />
                      </td>
                    </tr>
                    <!-- END -->
                    
                  </table>
                </center>
           </fieldset>      
           </td>
        </tr>
        <tr>
            <td style="border-style: none;">
            <fieldset>
                <legend ><strong>添加图片</strong></legend>
                <center>
                 <img id="route_image" src="{route.route_image}" />
                 <br />
                <table>
                <tr>
                    <td >上传文件：</td>
                    <td >
                        
                    </td>
                </tr>
                <tr>
                    <td ><input type="file" name="file" id="file"/></td>
                    <td >
                        <input type="button"  value="上传" onclick="TFileUpload();"/>
                    </td>
                </tr>
                </table>
                
                </center>
           </fieldset>      
           </td>
        </tr>
        <tr>
            <td style="border-style: none;">
            <fieldset>
                <legend ></legend>
                <center>
                <input type="button" value="修 改" onclick="submit_form();" />
                </center>
           </fieldset>      
           </td>
        </tr>
    </table>
  </center>
</form>
<script>
function TFileUpload()
{
    var upurl = "/adminweb/w-route/addImage?id={route.id}&cache="+Math.random();
    $.ajaxFileUpload({
            url:upurl,
            secureuri:false,
            fileElementId:'file',
            dataType: 'json',
            success: function (data, status)
            {
                if(data.success)
                {
                    after_TFileUpload(data);
                    alert('上传成功');
                    
                }else{
                    alert(data.msg);
                }
            },
     })   
}
                        /*上传的文件，成功地址*/
                        function after_TFileUpload(json)
                        {
                            //alert(json.src);
                            $("#route_image").attr('src','/'+json.data.file);
                            //window.location.reload();
                        }       
                        /*提交表单*/
                        function submit_form()
                        {
                            var data = new Array();
                            data['form[ico]']=$("#ico").val();
                        
                            var data_str='';
                            for(i in data)
                            {
                                data_str +=i+'='+data[i]+'&';
                            }
                            data_str += "form[id]={route.id}&cache="+Math.random();
                            //alert(data_str);return;
                            $.ajax({
                                    url:'{url}',
                                    data:data_str,
                                    //dataType:'json',
                                    type:'post',
                                    success:function(json){
                                        alert(json);
                                        window.location.reload();
                                    }
                                });
                        }
                    
                    </script>

</body>
</html>